﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;
using Microsoft.Phone.UserData;

namespace SLRTHackathon.Views
{
    public partial class CallPage : PhoneApplicationPage
    {
        public CallPage()
        {
            InitializeComponent();
        }

        private void ContactsBtn_Click(object sender, RoutedEventArgs e)
        {
            PhoneNumberChooserTask phoneNumberChooserTask = new PhoneNumberChooserTask();
            phoneNumberChooserTask.Completed += new EventHandler<PhoneNumberResult>(phoneNumberChooserTask_Completed);
            phoneNumberChooserTask.Show();
        }

        void phoneNumberChooserTask_Completed(object sender, PhoneNumberResult e)
        {
            PhoneCallTask phoneCallTask = new PhoneCallTask();
            phoneCallTask.PhoneNumber = e.PhoneNumber;
            phoneCallTask.Show();
        }


        private void BackBtn_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Views/CarDockPage.xaml", UriKind.RelativeOrAbsolute));
        }

        private void Favorite3Btn_Click(object sender, RoutedEventArgs e)
        {
            Contacts cons = new Contacts();

            //Identify the method that runs after the asynchronous search completes.
            cons.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(cons_SearchCompleted);
            //Start the asynchronous search.
            cons.SearchAsync("Chris Sells", FilterKind.DisplayName, "Chris Sells");
        }

        private void DiallerBtn_Click(object sender, RoutedEventArgs e)
        {
            PhoneCallTask phoneCallTask = new PhoneCallTask();
            phoneCallTask.PhoneNumber = "";
            phoneCallTask.Show();
        }

        private void Favorite2Btn_Click(object sender, RoutedEventArgs e)
        {
            Contacts cons = new Contacts();

            //Identify the method that runs after the asynchronous search completes.
            cons.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(cons_SearchCompleted);
            //Start the asynchronous search.
            cons.SearchAsync("Roan Kang", FilterKind.DisplayName, "Roan Kang");
        }

        void cons_SearchCompleted(object sender, ContactsSearchEventArgs e)
        {
            PhoneCallTask phoneCallTask = new PhoneCallTask();
            phoneCallTask.PhoneNumber = e.Results.ElementAt(0).PhoneNumbers.ElementAt(0).PhoneNumber;
            phoneCallTask.Show();
        }

        private void RecentBtn_Click(object sender, RoutedEventArgs e)
        {
            PhoneNumberChooserTask phoneNumberChooserTask = new PhoneNumberChooserTask();
            phoneNumberChooserTask.Completed += new EventHandler<PhoneNumberResult>(phoneNumberChooserTask_Completed);
            phoneNumberChooserTask.Show();
        }

        private void Favorite1Btn_Click(object sender, RoutedEventArgs e)
        {
            Contacts cons = new Contacts();

            //Identify the method that runs after the asynchronous search completes.
            cons.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(cons_SearchCompleted);
            //Start the asynchronous search.
            cons.SearchAsync("Andrew Hill", FilterKind.DisplayName, "Andrew Hill");
        }

        private void BluetoothBtn_Click(object sender, RoutedEventArgs e)
        {
            ConnectionSettingsTask connectionSettingsTask = new ConnectionSettingsTask();
            connectionSettingsTask.ConnectionSettingsType = ConnectionSettingsType.Bluetooth;
            connectionSettingsTask.Show();
        }
    }
}